package com.quxian.chambercommerce.dao.impl;

import java.util.List;

import com.quxian.chambercommerce.base.BaseDaoSupport;
import com.quxian.chambercommerce.bean.PublicNoticeEntity;
import com.quxian.chambercommerce.dao.PublicNoticeDao;
import com.quxian.chambercommerce.searchCondition.CommonSearchBean;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-11-6
 * Time: 下午11:04
 * To change this template use File | Settings | File Templates.
 */
public class PublicNoticeDaoImpl extends BaseDaoSupport implements PublicNoticeDao {
    @Override
    public void addPublicNotice(PublicNoticeEntity entity) {
       super.getSqlMapClientTemplate().insert("addPublicNotice",entity);
    }

    @Override
    public void deletePublicNoticeById(Integer id) {
        super.getSqlMapClientTemplate().delete("deletePublicNotice",id);
    }

    @Override
    public void updatePublicNotice(PublicNoticeEntity entity) {
        super.getSqlMapClientTemplate().update("updatePublicNotice",entity);
    }

    @Override
    public List<PublicNoticeEntity> getPublicNoticeList() {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public PublicNoticeEntity getPublicNoticeById(Integer id) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<PublicNoticeEntity> getPublicNoticeList(CommonSearchBean searchBean)
    {
    	if(searchBean == null)
    	{
    		return (List<PublicNoticeEntity>)getSqlMapClientTemplate().queryForList("PublicNotice.getPublicNoticeList");
    	}
    	PublicNoticeEntity entity = new PublicNoticeEntity();
    	entity.setTitle("%" + searchBean.getKeyword() + "%");
    	Integer count = (Integer)getSqlMapClientTemplate().queryForObject("PublicNotice.getPublicNoticeListCount", entity);
    	searchBean.setTotalCount(count);
    	return (List<PublicNoticeEntity>)getSqlMapClientTemplate().queryForList("PublicNotice.getPublicNoticeList", entity, (searchBean.getPageNo() - 1) * searchBean.getPageSize(), searchBean.getPageSize());
    }
}
